<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>sketch-color-picker</title>
  <script src="../dist/sketch-color-picker.js"></script>
</head>

<body>
  <style>
    .sketch-color-wrapper {
      display: flex;
      position: absolute;
      left: 50%;
      top: 10%;
    }
    .sketch-color-wrapper span {
      display: inline-block;
      width: 120px;
      user-select: none;
    }
    .sketch-color-box {
      padding: 10px 20px;
      border-radius: 2px;
      outline: 1px solid #ccc;
      outline-offset: 4px;
    }
    img {
      display: block;
      width: 100%;
    }
  </style>

    <div class="sketch-color-wrapper">
      <label class="btn">点击我打开：</label>  
      <div class="sketch-color-box"></div>
    </div>
  <script>

    var initColor = 'rgba(255,0,255,0.5)' // #7ed321
    var btn = document.querySelector('.btn');
    var sketchBox = document.querySelector('.sketch-color-box');
    var Picker = new SketchColorPicker(sketchBox, {
      color: initColor,
      onChange: function(color){
        sketchBox.style.background = color.toRgbString()
      }
    })

    sketchBox.style.background = initColor;
    sketchBox.addEventListener('click', function(){
      // 通过visible 控制可见
      var visible = Picker.visible;
      Picker.visible = !visible
      btn.innerText = !visible ? '点击我关闭：' : '点击我打开：'
    })

    // Picker.destroy()
  </script>



</body>

</html>